package com.ruoyi.common.enums.business;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum CouponSourceTypeEnum {

    KOC_TASK(1, "KOC任务达成"),


    ;

    private final Integer type;

    private final String desc;


    private static final Map<Integer, CouponSourceTypeEnum> ENUM_MAP;

    static {
        CouponSourceTypeEnum[] values = values();
        Map<Integer, CouponSourceTypeEnum> enToCn = new HashMap<>(values.length);
        for (CouponSourceTypeEnum value : values) {
            enToCn.put(value.getType(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static CouponSourceTypeEnum getEnumByType(Integer type) {
        CouponSourceTypeEnum userPointsSourceTypeEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(userPointsSourceTypeEnum)) {
            throw new RuntimeException("类型有误");
        }
        return userPointsSourceTypeEnum;
    }

}
